package com.bolt.support.spring.jpa.jpql;

import com.bolt.common.utils.StrUtil;

/**
 * Created by Administrator on 2020/9/11.
 */
public class StitchClause extends BaseClause<String,StitchClause,String>  {

    public StitchClause(String clause) {
        super(clause, null, null, null);
    }

    @Override
    public String render(boolean addAlias) {
        StringBuffer to = new StringBuffer(60);
        if(null != this.ops){
            String funcPattern = templates.get(this.ops);
            this.args.add(0,this.property);
            to.append(StrUtil.indexedFormat(funcPattern,this.args));
        }else{
            to.append(this.property);
        }
        if(StrUtil.isNotBlank(this.alias) && addAlias){
            String pattern = templates.get(Ops.ALIAS);
            to.append(StrUtil.indexedFormat(pattern,this.alias));
        }
        return to.toString();
    }

    @Override
    public String getParamName() {
        return alias;
    }
}

 